
window.CKEditorParams={
	
	odoc_xuhao1 : -1,
	odoc_xuhao2 : -1,
	odoc_xuhao3 : -1,
	odoc_xuhao4 : -1,
	
	attachment : -1,
	numData : {
		odoc_xuhao1:["一、","二、","三、","四、","五、","六、","七、","八、","九、"],
		odoc_xuhao2:["（一）","（二）","（三）","（四）","（五）","（六）","（七）","（八）","（九）"],
		odoc_xuhao3:["1.","2.","3.","4.","5.","6.","7.","8.","9."],
		odoc_xuhao4:["（1）","（2）","（3）","（4）","（5）","（6）","（7）","（8）","（9）"],
	},	
	revisionStatus:false,//修订状态	
	endorseId:0,//批注序号 批注计数
	showPostil:true,//是否显示批注	
	insertId:0,//插入数据的id
	deleteId:0,//删除数据的id
	selectDelete:false,//是否是选择文字删除
	selectText:"",//选择的文本
	tempStr1:"",//获取焦点之前的文本
	//tempStr2:"",//获取焦点之后的文本
	start:0,//勾选的文字 所在节点的起始字符位置
	//end:0, //勾选的文字 所在节点的结束字符位置
	node:{},//勾选文字的节点
	author : "",//用户信息
	keyDownContinue :false, //是否值一直按着删除键
	deleteContinueCount:0,	//单条删除的文字计数
	insertContinueCount: 0,	//单条插入信息的文字的计数
	reviseCount:0, //修订计数
	reviseType : "insert",
	hoverDom:"",

}
var iframeWindow =""
var iframeDocument = "";


CKEditorParams.editorObject=CKEDITOR.replace( 'editor1',{   
	language : 'zh-cn',  
	extraPlugins: 'timestamp,pagebreak, listAdvance',
	on: {
	  pluginsLoaded: function() {
	    var editor = this,
	    config = editor.config;
	    
	    editor.ui.addRichCombo( 'my-combo', {
	        label: '序号',
	        title: '序号',
	        toolbar: 'clipboard,0',
	
	        panel: {               
	            css: [ CKEDITOR.skin.getPath( 'editor' ) ].concat( config.contentsCss ),
	            multiSelect: false,
	            attributes: { 'aria-label': 'My Dropdown Title' },
	        },
	
	        init: function() {    
	            this.add( '一，二，三', '一，二，三' );
	            this.add( '（一），（二），（三）', '（一），（二），（三）');                    
	            this.add( '1，2，3', '1，2，3');
	            this.add( '（1），（2），（3）', '（1），（2），（3）');                    
	        },
	
	        onClick: function(value){
	        	setNumber(value);
	        }
	    });
    
	    editor.ui.addRichCombo( 'attachment', {
	        label: '版式',
	        title: '版式',
	        toolbar: 'clipboard,0',
	        panel: {               
	            css: [ CKEDITOR.skin.getPath( 'editor' ) ].concat( config.contentsCss ),
	            multiSelect: false,
	            attributes: { 'aria-label': 'plate' },
	        },
	        init: function() {    
	          this.add( '附件', '附件' );
	          this.add( '附件(多个)', '附件(多个)' );
	          this.add('附注','附注')
	        },
	        onClick: function(value){
	        	insertAttachment(value);
	        }
	    });      
  	}
  }
});

var odocNumber = new CKEDITOR.style( { element: 'p', attributes: { 'class': 'odoc_wenhao' }} );
CKEditorParams.editorObject.addCommand( 'odocNumber', new CKEDITOR.styleCommand( odocNumber ) );

var docTitle = new CKEDITOR.style( { element: 'p', attributes: { 'class': 'odoc_zhubiaoti' }} );
CKEditorParams.editorObject.addCommand( 'docTitle', new CKEDITOR.styleCommand( docTitle ) );

var fubiaoti = new CKEDITOR.style( { element: 'p', attributes: { 'class': 'odoc_fubiaoti' }} );
CKEditorParams.editorObject.addCommand( 'fubiaoti', new CKEDITOR.styleCommand( fubiaoti ) );

var zhusong  = new CKEDITOR.style( { element: 'p', attributes: { 'class': 'odoc_zhusong' }} );
CKEditorParams.editorObject.addCommand( 'zhusong', new CKEDITOR.styleCommand( zhusong ) );

var zhengwen = new CKEDITOR.style( { element: 'p', attributes: { 'class': 'odoc_zhengwen' }} );
CKEditorParams.editorObject.addCommand( 'zhengwen', new CKEDITOR.styleCommand( zhengwen ) );

var shuming = new CKEDITOR.style( {element: 'p', attributes: { 'class': 'odoc_shuming1' }} );
CKEditorParams.editorObject.addCommand( 'shuming', new CKEDITOR.styleCommand( shuming ) );

var shuming = new CKEDITOR.style( {element: 'p', attributes: { 'class': ' odoc_shuming1' }} );
CKEditorParams.editorObject.addCommand( 'shuming', new CKEDITOR.styleCommand( shuming ) );

var fuzhu = new CKEDITOR.style( {element: 'p', attributes: { 'class': ' odoc_fuzhu' }} );
CKEditorParams.editorObject.addCommand( 'fuzhu', new CKEDITOR.styleCommand( fuzhu ) );

var qianshuriqi = new CKEDITOR.style( { element: 'p', attributes: { 'class': 'odoc_qianshuriqi1' }} );
CKEditorParams.editorObject.addCommand( 'qianshuriqi', new CKEDITOR.styleCommand( qianshuriqi ) );
var ck = {
  updateAll: function () {
    for (instance in CKEDITOR.instances) {
      CKEDITOR.instances["editor1"].updateElement();
    }
  },
  resetAll: function () {
    for (instance in CKEDITOR.instances) {
      CKEDITOR.instances["editor1"].setData("");
    }
  },
  update: function () {
    CKEDITOR.instances["editor1"].updateElement();
  },
  reset: function () {
    CKEDITOR.instances[id].setData("");
  },
  set: function ( content) {
    CKEDITOR.instances["editor1"].setData(content,function(){
		ready(true)
	});
  },
  get: function() {
    return CKEDITOR.instances["editor1"].getData();
  },
  insert: function ( content) {
    CKEDITOR.instances["editor1"].insertHtml(content);
  }
};
	
var needChangFlag = false;
/** change事件 */
CKEditorParams.changeCount = 0;
CKEditorParams.editorObject.on( 'change', function(event) {

	if(window.console)console.log( '------------------ change' ,event.data); 
	setUTagDesc(event);
	setSTagDesc(event);
	//修订时
	if(CKEditorParams.revisionStatus 
		&& CKEditorParams.needChange
		&& CKEditorParams.editorObject.getSelection().getNative().focusNode.tagName != 'U' 
		&& CKEditorParams.editorObject.getSelection().getNative().focusNode.parentNode.tagName != 'U'
		&& CKEditorParams.changeCount <= 100 
		){
		// CKEditorParams.changeCount++;
		// CKEditorParams.needChange = false;
		// var range = CKEditorParams.editorObject.createRange();
		// var uElement = CKEDITOR.dom.element.createFromHtml( '<u class="odoc_insertTag" ></u>' );
		// CKEditorParams.editorObject.insertElement( uElement );
		
		// range.moveToPosition( uElement, CKEDITOR.POSITION_BEFORE_END);
		// range.select();
	}



	// if(CKEditorParams.revisionStatus && !jQuery("#cke_42").hasClass("cke_button_on"))
	// CKEditorParams.editorObject.execCommand('Underline');
	
	// if(!CKEditorParams.revisionStatus && jQuery("#cke_42").hasClass("cke_button_on"))
	// CKEditorParams.editorObject.execCommand('Underline');
	
		// if(CKEditorParams.revisionStatus && !jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);
		
		// if(!CKEditorParams.revisionStatus && jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);
});

CKEditorParams.editorObject.on( 'setData', function(event) {
	
});

/** keydown事件 */
CKEditorParams.editorObject.on("key", function(event){
	CKEditorParams.needChange=false;
	var e = event.data.domEvent.$;
	setUTagDesc(event);
	if(window.console)console.log(e.keyCode)
	if(e.keyCode == 8 || e.keyCode == 1 ||  e.keyCode == 46){
		// if(CKEditorParams.revisionStatus && !jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);
		
		// if(!CKEditorParams.revisionStatus && jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);
	}else{
		// if(!jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);

		// //输入内容时
		// var activeObj = CKEditorParams.editorObject.getSelection().getNative().focusNode;
		// if(activeObj.tagName == 'U' || activeObj.parentNode.tagName == 'U'){

		// }else{

		// 	var range = CKEditorParams.editorObject.createRange();
		// 	var uElement = CKEDITOR.dom.element.createFromHtml( '<u class="odoc_insertTag" ></u>' );
		// 	CKEditorParams.editorObject.insertElement( uElement );
			
		// 	range.moveToPosition( uElement, CKEDITOR.POSITION_AFTER_START);
		// 	range.select();
		// }
		return;
	}

	if(e.keyCode == 17 ){
		return;
	}
	//修订时
	if(CKEditorParams.revisionStatus){
		//如果没有选中内容，而且不是删除内容时，不需要添加删除痕迹
		if(CKEditorParams.selectDelete){
			if(e.keyCode != 8  && e.keyCode != 46){
				event.cancel();
				return ;
			}
		}
		//删除内容
		if(e.keyCode == 8 || e.keyCode == 46){
			var isDelKey = (e.keyCode == 46);
			//clearInsTag();
			if(event.editor.getSelection().getStartElement() && event.editor.getSelection().getStartElement().getAttribute("class") == "odoc_insertTag" && event.editor.getSelection().getStartElement().getText().replace(/\u200B/g,'') != ""){
				return;
			}else{
				//删除临时生成的U标签
				if(event.editor.getSelection().getStartElement() && event.editor.getSelection().getStartElement().getAttribute("class") == "odoc_insertTag" && event.editor.getSelection().getStartElement().getText().replace(/\u200B/g,'') == ""){
					event.editor.getSelection().getStartElement().$.remove();
				}
				// if(CKEditorParams.deleteContinueCount == 0){
				// 	if(iframeWindow.getSelection().extentNode && iframeWindow.getSelection().extentNode.parentElement){
				// 		if(iframeWindow.getSelection().extentNode.parentElement.tagName != "BODY"){
				// 			CKEditorParams.node = iframeWindow.getSelection().extentNode.parentElement;
				// 		}else{
				// 			CKEditorParams.node = iframeWindow.getSelection().extentNode;
				// 		}
				// 	}
				// }else{
				// 	CKEditorParams.node = iframeWindow.getSelection().baseNode.parentNode;
				// }
				
				//修订痕迹ID计数
				CKEditorParams.deleteContinueCount += 1;
				CKEditorParams.deleteId += 1;
				CKEditorParams.insertId += 1;
				//选中内容删除时
				if(event.editor.getSelection().getSelectedText().length > 0){
					deleteSelected(event,isDelKey)
					event.cancel();
				}else{

					//不选中内容删除时
					if(CKEditorParams.tempStr1=='' && CKEditorParams.editorObject.getSelection().getStartElement().$.tagName == 'P'){
						event.cancel();
						return;
					}
					deleteOne(event,isDelKey);
					
				}
			}
			
		}else if(e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 38 || e.keyCode == 40 || e.keyCode == 13){
			CKEditorParams.needChange=true;
			CKEditorParams.editorObject.fire('change');
		}else{
			CKEditorParams.needChange=false;
		}
	// }else{
	// 	var keyCode = e.keyCode || e.which || e.charCode;
	// 	if(keyCode == 8){
	// 		deleteSequence();
	// 	}
	// 	preventKey(e,keyCode)
	}
});

/** 拒绝修订 */
function rejectChange(dom){
	if(!CKEditorParams.revisionStatus){
		return ;
	}
	var insertTagItem = iframeDocument.getElementsByClassName("odoc_insertTagInline"); 
	for(var i = 0 ; i < insertTagItem.length;i++){
		insertTagItem[i].remove();
		i--;
	}
	
	dom.className="disabled";
}

/** 拒绝修订可以点击 */
function rejectChangeCanClick(){
	document.getElementById("rejectChange").setAttribute("class","");
}

/** 拒绝修订不可以点击 */
function rejectChangeCannotClick(){
	document.getElementById("rejectChange").setAttribute("class","disabled");
}


/** 清除没有内容的ins标签 */
function clearInsTag(){
	var insertTagItem = iframeDocument.getElementsByClassName("odoc_insertTag");
	for(var i = 0 ; i < insertTagItem.length;i++){
		if(insertTagItem[i].innerText == ""){
			insertTagItem[i].remove();
			i--;
		}
	}
}

/** 清除才生成的ins标签 */
function clearLastIns(){
	var insertTagItem = iframeDocument.getElementById("insertTag"+CKEditorParams.insertId);
	if(insertTagItem){
		insertTagItem.remove();
	}
}

/** 设置序号 */
function setNumber(value){
  if(value == '1'){
    CKEditorParams.editorObject.execCommand('listAdvance-ChCpt');
  }else if(value == '2'){
    CKEditorParams.editorObject.execCommand('listAdvance-ChCptP');
  }else if(value == '3'){
    CKEditorParams.editorObject.execCommand('listAdvance-Number');
  }else if(value == '4'){
    CKEditorParams.editorObject.execCommand('listAdvance-NumberP');
  }
	/*var numData = CKEditorParams.numData;
	var className="";  		
	if(value == '1'){
		className = "odoc_xuhao1";
		CKEditorParams.odoc_xuhao1 += 1;
		CKEditorParams.odoc_xuhao2 = -1;
	}else if(value == '2'){
		className = "odoc_xuhao2";
		CKEditorParams.odoc_xuhao2 += 1;
		CKEditorParams.odoc_xuhao3 = -1;
		CKEditorParams.odoc_xuhao4 = -1;
	}else if(value == '3'){
		className = "odoc_xuhao3";
		CKEditorParams.odoc_xuhao3 += 1;
		CKEditorParams.odoc_xuhao4 = -1;
	}else if(value == '4'){
		CKEditorParams.odoc_xuhao4 += 1;
		className = "odoc_xuhao4";
	}
	if(CKEditorParams[className] > 9 ){
		var index = parseInt(CKEditorParams[className].toString().split("")[1])+1 || 0;
	}
	//var element = CKEDITOR.dom.element.createFromHtml( '<span class="'+className+'" numData="' + numData[className][CKEditorParams[className]] + '">'+numData[className][CKEditorParams[className]]+'</span>' );
	
	var element = CKEDITOR.dom.element.createFromHtml( '<span class="odoc_xuhao_temp" numData="' + numData[className][CKEditorParams[className]] + '">'+numData[className][CKEditorParams[className]]+'</span>' );
	//CKEditorParams.editorObject.insertElement(element);
	
	var selectElement = CKEditorParams.editorObject.getSelection().getStartElement();
	CkPTagcount = 0;
	var pTagEle = getCkPTag(selectElement);
	deleteTempSpan(pTagEle);
	pTagEle.append(element,true);
	pTagEle.setAttribute("class",className);
	//CKEditorParams.editorObject.insertElement(element);
	focusEditorByCkItem(element,true)*/;
}
		 

/** 插入附件标签 */
function insertAttachment(value){
	if(CKEditorParams.attachment > 8){
		CKEditorParams.attachment
	}
	var element;
	var classname="";
	//单个附件
	if(value == "11"){
		classname = 'odoc_fujian1';
		element = CKEDITOR.dom.element.createFromHtml( '<span class="odoc_fujian_temp" >附件：</span>' );
		//多个附件
	}else if(value == "12"){
		CKEditorParams.attachment += 1 ;
		var length = iframeDocument.getElementsByClassName("odoc_fujian2").length;
		if(length == 0){
			classname = 'odoc_fujian2';
			element = CKEDITOR.dom.element.createFromHtml( '<span class="odoc_fujian_temp" >附件：'+CKEditorParams.numData["odoc_xuhao4"][CKEditorParams.attachment]+'</span>' );
		}else{
			classname = 'odoc_fujian3';
			element = CKEDITOR.dom.element.createFromHtml( '<span class="odoc_fujian_temp" >'+CKEditorParams.numData["odoc_xuhao4"][CKEditorParams.attachment]+'</span>' );
		}
		//附注
	}else if(value == "13"){
		classname = 'odoc_fuzhu';
		element = CKEDITOR.dom.element.createFromHtml( '<span class="odoc_fuzhu_temp" >附注：</span>' );
	}
	var selectElement = CKEditorParams.editorObject.getSelection().getStartElement();
	CkPTagcount = 0;
	var pTagEle = getCkPTag(selectElement);
	deleteTempSpan(pTagEle);
	pTagEle.append(element,true);
	pTagEle.setAttribute("class",classname);
	//CKEditorParams.editorObject.insertElement(element);
	focusEditorByCkItem(element,true);
}
/**删除临时的SPAN标签 */
function deleteTempSpan(pTagEle){
	if(pTagEle == undefined) {
		var selectElement = CKEditorParams.editorObject.getSelection().getStartElement();
		CkPTagcount = 0;
		pTagEle = getCkPTag(selectElement);
	}
	
	for(let j=0;j<pTagEle.getChildCount();j++){
		
		var childNode = pTagEle.getChild(j);
		if(childNode.$.tagName == 'SPAN' && (childNode.getAttribute("class") == 'odoc_fujian_temp' || childNode.getAttribute("class") == 'odoc_xuhao_temp') ){
			//pTagEle.remove([childNode]);
			childNode.$.remove();
		}
	}
}
/** 根据CK的节点，递归查询最上层的P标签 */
CkPTagcount = 0;
function getCkPTag(element){
	if(element.$.nodeName == 'P') return element;
	if(CkPTagcount <= 10){
		CkPTagcount++;
		element = element.getParent();
		return getCkPTag(element);
	}
}

//修订
function revision(e){
	CKEditorParams.revisionStatus = !CKEditorParams.revisionStatus;
	showReviseList(!CKEditorParams.revisionStatus);
	
}
//打开或者选择文件以后
CKEditorParams.editorObject.on('elementsPathUpdate', function (e) { 	
	jQuery('.cke_wysiwyg_frame')[0].contentWindow.document.onclick = function(event){

		if(CKEditorParams.editorObject.getSelection().getSelectedText() == ""){
			//TODO
			// if(CKEditorParams.revisionStatus && !jQuery("#cke_42").hasClass("cke_button_on"))
			// CKEDITOR.tools.callFunction(79);
			
			//  if(!CKEditorParams.revisionStatus && jQuery("#cke_42").hasClass("cke_button_on"))
			//  CKEDITOR.tools.callFunction(79);
		}
	}
});
//初始化函数
CKEDITOR.on('instanceReady', function (e) { 	
	CKEditorParams.author = JSON.parse (localStorage.getItem("theme-account")).username;
	document.getElementById("author").innerText = CKEditorParams.author;
	try{
		var docInfo = parent.parent.parent.WfForm.getOdocConfig();
		if(docInfo.docParam.docid > 0 ){
		parent.readOnlineEditFile(docInfo.docParam.docid);
		}
	}catch(e){

	}
	
	try{
    	jQuery('#cke_1_contents').height(jQuery('body',parent.parent.window.document).height() - 138);
	}catch(e){

	}

	ready()
})

//初始化函数

function ready(bool){


	CKEditorParams.editorObject.focus();
		iframeDocument = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument;
		iframeWindow = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentWindow;
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	bool && getReviseItem() ;
	bool && getPositlItem() ;
	// iframeBody.addEventListener("click",bodyClick,false);
	iframeBody.onmousedown = function (){ 
		// console.log("------------onmousedown");
		// if(CKEditorParams.revisionStatus && !jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);
		
		// if(!CKEditorParams.revisionStatus && jQuery("#cke_42").hasClass("cke_button_on"))
		// CKEDITOR.tools.callFunction(79);
		//resetSelectedClass(iframeWindow.getSelection());
		return clearInsTag();
	}	
	iframeBody.onmouseup =  function (){
		resetSelectedClass(iframeWindow.getSelection());
		 return bindSelection();
	}
	//iframeBody.onkeyup = function (){ return deleteInsFrist();};
	iframeBody.onmouseover =function (e){ return showInfo(e);} 
	iframeBody.onclick = function(e){
		 console.log("------------onclick");
		if(e.target.className != "odoc_insertTag" && e.target.className != "odoc_postilWord" 
			&& e.target.className != "odoc_postilWord1" && CKEditorParams.revisionStatus 
			&& CKEditorParams.selectText==""){
			clearInsTag();
		}
		if(CKEditorParams.revisionStatus ){
			CKEditorParams.needChange = true;
			CKEditorParams.editorObject.fire('change');
		}
	}
	iframeBody.onkeydown = function(){
		 console.log("------------onkeydown");

	};

	iframeBody.onkeyup = function(){
		 console.log("------------onkeyup");
		CKEditorParams.keyDownContinue = false;
	}
	//是否显示修订
	showReviseList(!CKEditorParams.revisionStatus);
	// if(!CKEditorParams.revisionStatus){
		
	// 	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	// 	var delList = iframeBody.getElementsByTagName("s")
	// 	var insList = iframeBody.getElementsByTagName("u")
	// 	for(var i =0; i < delList.length;i++){
	// 		jQuery(delList[i]).addClass('hiddenRevision');
	// 	}
	// 	for(var i =0; i < insList.length;i++){
	// 		jQuery(insList[i]).addClass('hiddenRevision');
	// 	}
	// }
}

//勾选文字事件
function bindSelection(e){
	
	if(CKEditorParams.revisionStatus){
		addRevise()
		clearInsTag();
	}
	
	CKEditorParams.insertContinueCount = 0
	CKEditorParams.deleteContinueCount = 0;
	
	var getSelected = iframeWindow.getSelection;
	CKEditorParams.selectText =  getSelected ? getSelected().toString():iframeDocument.selection.createRange().text;
//	CKEditorParams.node =	CKEditorParams.editorObject.getSelection().getRanges()[0].startContainer
		
  CKEditorParams.node= iframeWindow.getSelection().extentNode && iframeWindow.getSelection().extentNode.parentElement || null;
// CKEditorParams.node.innerHTML = CKEditorParams.node.innerHTML
	CKEditorParams.start = getSelected().focusOffset;
	CKEditorParams.end = getSelected().anchorOffset;

	
	try{

		CKEditorParams.tempStr1 = CKEditorParams.editorObject.getSelection().getCommonAncestor().$.wholeText.replace(/\u200B/g,'').substring(0,CKEditorParams.end); 
		CKEditorParams.tempStr2 = CKEditorParams.node.innerText.substring(CKEditorParams.start,CKEditorParams.node.innerText.length)
		if(CKEditorParams.selectText != ""){
			CKEditorParams.selectDelete = true;
			CKEditorParams.startIndex = CKEditorParams.node.innerText.indexOf(CKEditorParams.selectText);
		// creatPostilCanClick()
		}else{
			CKEditorParams.selectDelete = false;
			CKEditorParams.startIndex = CKEditorParams.start;
		// creatPostilCannotClick()
			
		}
	}catch(e){

	}
	
}

CKEditorParams.editorObject.on( 'blur', function(e) {

  CKEditorParams.deleteContinueCount = 0;
  
});

function deleteInsFrist(){
	var insDom = iframeDocument.getElementById("insertTag"+insertId);
	if(CKEditorParams.deleteContinueCount == 1 && insDom.innerText.length>1){
		insDom.innerText = insDom.innerText.slice(0,-1)
	}
}

/** 点击新建批注 */
function creatPostil(){
	if(CKEditorParams.selectText ==""){
		document.getElementsByClassName("ant-modal-content")[0].style.display = "block";
		return;
	}
	if(document.getElementsByClassName("creatPostil")[0].style.display =="block"){
		return;
	}
	showPostilList(false);
	CKEditorParams.endorseId ++ ;






	var createdElement1 = CKEDITOR.dom.element.createFromHtml( "<span class='odoc_postilWord' _tempid='postilWord"+CKEditorParams.endorseId+"' id='"+CKEditorParams.endorseId+"'>"+CKEditorParams.selectText+"</span>" );

	
	CKEditorParams.editorObject.insertElement( createdElement1 );
	document.getElementsByClassName("creatPostil")[0].style.display="block";
	
	focusEditor(CKEditorParams.endorseId);



	// var html = "<span class='odoc_postilWord' _tempid='postilWord"+CKEditorParams.endorseId+"' id='"+CKEditorParams.endorseId+"'>"+CKEditorParams.selectText+"</span>"; 
	// html = CKEditorParams.tempStr1 +html + CKEditorParams.tempStr2;
	// CKEditorParams.node.innerHTML = html
	// //CKEditorParams.editorObject.insertHtml(html);
	// document.getElementsByClassName("creatPostil")[0].style.display="block";
	// document.getElementById("canEdit").focus();
}

//批注方法
function postil(){
	var textarea = document.getElementById("canEdit");
	var insertHtmlString='<div class="headPortrait"><span class="odoc_author">'+CKEditorParams.author+'</span></div><div class="postilContent"><div class="postilTime">'+getPostilDate()+'</div><div class="postilText">'+textarea.value+'</div></div>'	;
	var postilItem = document.createElement("div");
	postilItem.setAttribute("class","postilItem");
	postilItem.setAttribute("id","postilItem"+CKEditorParams.endorseId);		
	postilItem.innerHTML = insertHtmlString; 

	var nowTime = getDate()
	var postilWord = jQuery('span[_tempid="postilWord' + CKEditorParams.endorseId + '"]',iframeDocument);	
	postilWord.attr("pizhushijian",nowTime);
	postilWord.attr("pizhuren",CKEditorParams.author);
	postilWord.attr("pizhuneirong",textarea.value);	
	document.getElementById("postilBox").appendChild(postilItem)

	document.getElementById("postilNumber").innerText = CKEditorParams.endorseId + "处批注"

	creatPostilHide();
	noSelectText()
	// changePostilStatus()
}

//隐藏创建批注
function creatPostilHide(){
	document.getElementsByClassName("creatPostil")[0].style.display="none";
	document.getElementById("canEdit").value = "";
}

//获取第一个字符
function getFirstChar(tempString){
	tempString = tempString.replace(/\u200B/g,'');
	return tempString.substr(0,1);
}
//获取最后后一个字符
function getLastChar(tempString){
	tempString = tempString.replace(/\u200B/g,'');
	return tempString.substr(tempString.length-1,tempString.length);
}

//除去最后一个字符
function deleteLastChar(string){
	return string.substr(0,string.length-1);
}

//新建批注可以点击
function creatPostilCanClick(){
	document.getElementById("creatPostil").setAttribute("class","");
}

//新建批注不能点击
function creatPostilCannotClick(){
	document.getElementById("creatPostil").setAttribute("class","disabled");
}

//没有选择的文字清空
function noSelectText(){
	CKEditorParams.selectText = ""; 
	// creatPostilCannotClick()
}

//取消新建批注
function closeCreatPostil(e){
	e.parentElement.style.display="none";
	document.getElementById("canEdit").value="";
	var selectDom = iframeDocument.getElementById("postilWord"+CKEditorParams.endorseId);
	CKEditorParams.editorObject.insertHtml("<p>"+selectDom.innerText+"</P>");
	selectDom.remove();
	CKEditorParams.endorseId --;
	noSelectText()
}
			
//删除批注
function deletePostil(e){
	
	var AllPostilList = getByClassesAndId(['odoc_postilWord']);
	if(AllPostilList.length <= 0) return;
	if(selectedPostilNum < 0){
		selectedPostilNum = 0;
	}
	if(selectedPostilNum >= AllPostilList.length){
		selectedPostilNum = AllPostilList.length - 1;
	}
	focusEditorByItem(AllPostilList[selectedPostilNum]);
	AllPostilList[selectedPostilNum].outerHTML=AllPostilList[selectedPostilNum].innerHTML;
}	
//删除批注
function deleteAllPostil(e){
	
	var AllPostilList = getByClassesAndId(['odoc_postilWord']);
	if(AllPostilList.length <= 0) return;
	for(var i = 0 ; i < AllPostilList.length; i++){
		AllPostilList[i].outerHTML=AllPostilList[i].innerHTML;
	}
}

//点击批注 显示对应的批注
function bodyClick(ev){
	var ev = ev || event;
	var target = ev.target || ev.srcElement;
	if(target.className == "odoc_postilWord"){
		if(target.className == ""){
			return;
		}
		showPostil(target)
	}else{
		hidePostil()
	}
}

//显示批注
function showPostil(target){
	hidePostil();
	var number = getLastChar(target.getAttribute("id"));
	var postilItem = document.getElementById("postilItem"+number);
	postilItem.style.display="block";
}

//隐藏批注
function hidePostil(id){
	if(id){
		document.getElementById(id).style.display="none";
	}else{
		var postilItemList = document.getElementsByClassName("postilItem");
		for(var i = 0;i<postilItemList.length;i++){
			postilItemList[i].style.display="none";
		}
	}
}

//批注文本背景颜色显隐
function showPostilWord(){
	if(!CKEditorParams.showPostil){
		changePostilShow();
	}else{
		//changePostilhide();
	}
}

//改变批注的状态为隐藏
function changePostilhide(){
	document.getElementsByClassName("showPostil")[0].innerText="显示批注"
	CKEditorParams.showPostil = false;
	var postilWordList = iframeDocument.getElementsByClassName("odoc_postilWord");
	for(var i=0 ;i<postilWordList.length;i++){
		postilWordList[i].className= "odoc_postilWord1";
		i--;
	}
	hidePostil();
}

//改变批注的状态为显示
function changePostilShow(){
	changePostilStatus();
	var postilWordList = iframeDocument.getElementsByClassName("odoc_postilWord1");
	for(var i=0 ;i<postilWordList.length;i++){
		postilWordList[i].className= "odoc_postilWord";
		i--;
	}
}

function changePostilStatus(){
	document.getElementsByClassName("showPostil")[0].innerText="不显示批注"
	CKEditorParams.showPostil = true;
}

//获取当前时间
function getDate(){
	var nowDate = new Date();
	var year = nowDate.getFullYear();
	var month = resetTime(nowDate.getMonth()+1);
	var date =  resetTime(nowDate.getDate());
	var hour =  resetTime(nowDate.getHours());
	var minute = resetTime(nowDate.getMinutes());
	var second = resetTime(nowDate.getSeconds());
	var nowTime = year+"-"+month+"-"+date+"T"+hour+":"+minute+":"+second+"Z";
	return nowTime;
}

//获取批注当前时间
function getPostilDate(){
	var nowDate = new Date();
	var year = nowDate.getFullYear();
	var month = resetTime(nowDate.getMonth()+1);
	var date =  resetTime(nowDate.getDate());
	var hour =  resetTime(nowDate.getHours());
	var minute = resetTime(nowDate.getMinutes());
	var second = resetTime(nowDate.getSeconds());
	var nowTime = year+"-"+month+"-"+date+"&nbsp;"+hour+":"+minute+":"+second;
	return nowTime;
}

function resetTime(time){
	if(time > 9){
		return time;
	}else{
		return "0"+time;
	}
}

/** 保存方法 */
function submit(){
	var bodyDom = iframeDocument.getElementsByTagName("body")[0];
	var spanTags = bodyDom.getElementsByTagName("span");
	for(var i in spanTags){
		if(spanTags[i].className == "" || spanTags[i].className == "odoc_hide"){
			spanTags[i].outerHTML = spanTags[i].innerHTML;
			i--;
		}
	}

	var pTagList = iframeDocument.getElementsByTagName("body")[0].getElementsByTagName("p");
	//如果P标签没有样式，默认增加正文样式
	for(let i = 0;i < pTagList.length; i++){
		var pTagItem = pTagList[i];
		if(pTagItem.getAttribute("class") == "")pTagItem.setAttribute("class","odoc_zhengwen")
	}
	var tempRestltHtml = iframeDocument.getElementsByTagName("body")[0].innerHTML;
	
	//去除临时标签
	spanTags = bodyDom.getElementsByTagName("span");
	for(var i in spanTags){
		if(spanTags[i].className == 'odoc_xuhao_temp'){
			spanTags[i].remove();
			i--;
		}
	}

	var divTag = document.createElement("div");
	
	
	for(let i = 0;i < pTagList.length; i++){
		var pTagItem = pTagList[i];
		for(let j=0;j<pTagItem.childNodes.length;j++){
			var childNode = pTagItem.childNodes[0];
			if(childNode.getAttribute && childNode.getAttribute("class") != null)childNode.setAttribute("class",childNode.getAttribute("class").trim());
			if(childNode.tagName != 'FT'){
				var ftTag = document.createElement("ft");
				ftTag.appendChild(childNode);
				pTagList[i].appendChild(ftTag)
			}else{
				pTagList[i].appendChild(childNode)
			}
		}
		
		divTag.appendChild(pTagList[i])
		i--;
	}
	var resultString = divTag.innerHTML;
	
	resultString = resultString.replace(/\u200B/g,"");
	resultString = resultString.replace(/&nbsp;/g," ");
	resultString = resultString.replace(/id="postilWord/g,'id="');
	resultString = resultString.replace(/id="deltest_/g,'id="');
	resultString = resultString.replace(/<br>/g,'');
	resultString = resultString.replace(/<br\/>/g,'');
	if(window.console)console.log("resultString",resultString);
	ck.set(tempRestltHtml);
	return resultString;
}
//整理S标签
function setSTagDesc(event){
	if(CKEditorParams.editorObject.getSelection().getNative().focusNode == null){
		return;
	}
	var parentPObj = getPTagNode(CKEditorParams.editorObject.getSelection().getNative().focusNode,0);
	jQuery(parentPObj).find("S").each(function(index,ele){
		for(var i = 0 ; i < ele.childNodes.length; i++){
			ele.normalize();
		}
	});
}
//遍历U标签，填充信息
function setUTagDesc(event){
	
	//U标签加上ID
	var UTags = iframeDocument.getElementsByTagName("body")[0].getElementsByTagName("u");
	var maxid = 1;
	//获取最大的ID
	for(var i = 0;i < UTags.length; i++){
		var UTag = UTags[i];
		//删除内容为空的标签
		if(UTag.innerHTML =='' || UTag.innerHTML.replace(/\u200B/g,"")){
			UTag.remove();
			i--;
			continue;
		} 
		if(UTag.getAttribute("id") != '' && parseInt(UTag.getAttribute("id"),10) >= 0){
			var uid = parseInt(UTag.getAttribute("id"));
			maxid = maxid > uid ? maxid : uid;
		} 
	}
	//设置没有ID的标签
	for(var i = 0;i < UTags.length; i++){
		var UTag = UTags[i];
		UTag.innerHTML = UTag.innerHTML.replace(/\u200B/g,'')
		if(!(parseInt(UTag.getAttribute("id"),10) > 0)){
			if(UTag.innerHTML =='' || UTag.innerHTML.replace(/\u200B/g,'') == ''){
				continue;
			}
			maxid++;
			UTag.setAttribute("id",maxid);
			UTag.setAttribute("class",'odoc_insertTag');
			UTag.setAttribute("xiudingren",CKEditorParams.author);
			UTag.setAttribute("xiudingshijian",getDate());
			
			//insertReviseItem(UTag,'ins');
		}
		setSingleReviseItem(UTag,'ins');
	}
}

function moveToLeft(){
	var sel = CKEditorParams.editorObject.getSelection();
	var element = sel.getStartElement();
	//	sel.selectElement(element); 选择当前
	var findString;
	if(CKEditorParams.selectDelete){
//		findString = CKEditorParams.selectText;
//		
//		CKEditorParams.tempStr1 = CKEditorParams.tempStr1.slice(0,parseInt(-CKEditorParams.selectText.length))
	}else{
		findString = getLastChar(CKEditorParams.tempStr1)
		CKEditorParams.tempStr1 = CKEditorParams.tempStr1.slice(0,-1)
	}
	
	var ranges = sel.getRanges();
//	var startIndex = element.getHtml().indexOf(findString);
	if(CKEditorParams.deleteContinueCount > 0){
		CKEditorParams.startIndex -= 1;
	}
	var startIndex = CKEditorParams.startIndex;
	if (startIndex > -1) {
    ranges[0].setStart(element.getFirst(), startIndex);
    ranges[0].setEnd(element.getFirst(), startIndex);
    sel.selectRanges([ranges[0]]);
	}
	
	CKEditorParams.selectDelete = false;
}


function deleteSequence(){
		var sel = CKEditorParams.editorObject.getSelection()
		var ranges = sel.getRanges()[0]
		var previousNode = CKEditorParams.editorObject.getSelection().getRanges()[0].getPreviousNode()
		
		if(previousNode.$.parentElement.className.indexOf("xuhao") >-1){
			sel.selectElement(previousNode)
			CKEditorParams[previousNode.$.parentElement.className]--;
		}
}

function preventKey(e,keyCode){
	var ctrlKey = e.ctrlKey || e.metaKey;
  if(ctrlKey && keyCode == 86) {// ctrl + v
     CKEDITOR.tools.callFunction(22,this);
  }  
  if(ctrlKey && keyCode == 85){// ctrl + U
  	 event.cancel();
  }
  if(ctrlKey && keyCode == 73){//ctrl + I
  	 event.cancel();
  }
  if(ctrlKey && keyCode == 79){//ctrl + O
  	 event.cancel();
  }
  if(ctrlKey && keyCode == 89){//ctrl + v
  	CKEDITOR.tools.callFunction(28,this);
  }
  if(ctrlKey && keyCode == 66){//ctrl + B
  	event.cancel();
  }
}

function getNodePtag(node){
	var pTag = node.parentNode;
	if(pTag.tagName !=="P"){
		getNodePtag(pTag);
	}else{
		return pTag;
	}
}

function insertReviseItem(text,type){
	var reviseContent = document.getElementsByClassName("revise-content")[0];
	var typeText=""
	var titleNumberDom = document.getElementsByClassName("title-number")[0];
	var div = document.createElement("div");
	div.setAttribute("class","revise-item")
	div.setAttribute("id","reviseItem"+CKEditorParams.reviseCount)
	if(type == "insert"){
		typeText="插入的内容";
	}else{
		typeText="删除的内容"
	}
	div.innerHTML = '<div class="revise-top"><span class="revise-item-name">'+CKEditorParams.author+'</span><span class="revise-item-type">'+typeText+'</span></div><div class="revise-bottom">'+text+'</div>';   
	reviseContent.appendChild(div);
	titleNumberDom.innerHTML = CKEditorParams.reviseCount+"处修订";
}

function addRevise(){
  	var dom= ""
	  if(CKEditorParams.reviseType == "insert" ){
	  	dom= iframeDocument.getElementById("insertTag"+CKEditorParams.insertId)
	  }else{
	  	dom= iframeDocument.getElementById("delItem"+CKEditorParams.deleteId)
	  }
		
		var reviseitem = document.getElementById("reviseItem"+CKEditorParams.reviseCount);
		if(reviseitem == null){
			dom && insertReviseItem(dom.innerText,CKEditorParams.reviseType)
		}else{
			try{
			var reviseInfoDom = reviseitem.getElementsByClassName("revise-bottom")[0];
			reviseInfoDom.innerText = dom.innerText;
			}catch(e){if(window.console)console.log(e)}
		}
}
var needAdd =false;
var createdElementid = '';
var lastElement = null
/** 删除单个文字 */
function deleteOne(event,isDelKey){
	/*
	//如果是该节点的前面没有文字，获取前一个节点的文字
	if(CKEditorParams.tempStr1=='') {
		// lastElement = CKEditorParams.editorObject.getSelection().getStartElement();
		// CKEditorParams.tempStr1 = CKEditorParams.editorObject.getSelection().getStartElement().getText();
		moveToPreviousElement(CKEditorParams.editorObject.getSelection().getNative().focusNode);
		if(CKEditorParams.editorObject.getSelection().getNative().focusNode().parentNode.tagName == 'P'){

		}
	}
	var lastChar = getLastChar(CKEditorParams.tempStr1);
	// if(CKEditorParams.tempStr1 == ""){
	// 		//if(lastChar == ""){
		
	// 	var selection = CKEditorParams.editorObject.getSelection().getStartElement();
	// 	moveToPreviousElement(CKEditorParams.editorObject.getSelection().getStartElement());
	// 	lastChar = getLastChar(CKEditorParams.editorObject.getSelection().getStartElement().getText());
	// }
	*/

	//根据当前光标位置，获取前一个字符
	//当前光标
	var activeObj = CKEditorParams.editorObject.getSelection().getNative().focusNode;

	//如果要删除的内容是已经删除的，只移动光标
	if(activeObj.tagName == 'S' || activeObj.parentNode.tagName == 'S' 
		//&& activeObj.parentNode.className == 'odoc_delTag'
		){
		var ActiveElement =   new CKEDITOR.dom.element(CKEditorParams.editorObject.getSelection().getNative().focusNode);
		
		if(isDelKey && CKEditorParams.editorObject.getSelection().getNative().focusOffset < activeObj.textContent){
			var bookmarks = CKEditorParams.editorObject.getSelection().createBookmarks2();
			bookmarks[0].startOffset = CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1;
			bookmarks[0].endOffset = CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1;
			CKEditorParams.editorObject.getSelection().selectBookmarks(bookmarks);
			event.cancel();
			return;
		}
		if(!isDelKey && CKEditorParams.editorObject.getSelection().getNative().focusOffset>0){
			var bookmarks = CKEditorParams.editorObject.getSelection().createBookmarks2();
			bookmarks[0].startOffset = CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1;
			bookmarks[0].endOffset = CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1;
			CKEditorParams.editorObject.getSelection().selectBookmarks(bookmarks);
			event.cancel();
			return;
		}
	}
	//如果要删除的内容是新修订的内容，直接删除
	if(activeObj.tagName == 'U' || activeObj.parentNode.tagName == 'U' 
		//&& activeObj.parentNode.className == 'odoc_delTag'
		){
		return;
	}

/*
	//如果要删除的内容是已经删除的，插入临时内容

		//如果要删除的内容是已经删除的，插入临时内容
		if(activeObj.parentNode.tagName == 'S' && activeObj.parentNode.className == 'odoc_delTag'){
			var ActiveElement =   new CKEDITOR.dom.element(CKEditorParams.editorObject.getSelection().getNative().focusNode);
			
			if(isDelKey && CKEditorParams.editorObject.getSelection().getNative().focusOffset < activeObj.textContent){
				var range = CKEditorParams.editorObject.createRange();
				range.moveToPosition(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1);


				CKEditorParams.editorObject.insertElement( uElement );
				range.setStart(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1);
				range.setEnd(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1);
				CKEditorParams.editorObject.getSelection().selectRanges( [ range ] );
				event.cancel();
				return;
			}
			if(!isDelKey && CKEditorParams.editorObject.getSelection().getNative().focusOffset>0){
				var range = CKEditorParams.editorObject.createRange();
				//range.moveToPosition(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1);
				range.setStart(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1);
				range.setEnd(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1);
				CKEditorParams.editorObject.getSelection().selectRanges( [ range ] );
				event.cancel();
				return;
			}
			// var ActiveElement =   new CKEDITOR.dom.element(CKEditorParams.editorObject.getSelection().getNative().focusNode);
			// if(isDelKey && CKEditorParams.editorObject.getSelection().getNative().focusOffset < activeObj.textContent){
			// 	var range = CKEditorParams.editorObject.createRange();
			// 	range.moveToPosition(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1);

			// 	range.setStart(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1);
			// 	range.setEnd(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset + 1);
			// 	range.select();
			// 	event.cancel();
			// 	return;
			// }
			// if(!isDelKey && CKEditorParams.editorObject.getSelection().getNative().focusOffset>0){
			// 	var range = CKEditorParams.editorObject.createRange();
			// 	range.moveToPosition(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1);
			// 	range.setStart(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1);
			// 	range.setEnd(ActiveElement,CKEditorParams.editorObject.getSelection().getNative().focusOffset - 1);
			// 	range.select();
			// 	event.cancel();
			// 	return;
			// }
		}
	}
		
	if(activeObj.getParent().$.tagName == 'S'){

		var range = CKEditorParams.editorObject.createRange();

		var uElement = CKEDITOR.dom.element.createFromHtml( '<u class="odoc_insertTag" >A</u>' );
		uElement.insertAfter( createdElement );

		range.moveToPosition( uElement, isDelKey?CKEDITOR.POSITION_AFTER_END:CKEDITOR.POSITION_BEFORE_START);
		range.select();
		createdElement.$.outerHTML = createdElement.getHtml();
		uElement.remove();
		return;
	}
	*/

	//该段落的P标签
	var parentPObj = getPTagNode(CKEditorParams.editorObject.getSelection().getNative().focusNode,0);

	//获取range对象
	var selectRange = CKEditorParams.editorObject.getSelection().document.$.createRange();
	//如果是DEL按钮事件，从光标开始向后获取
	if(isDelKey){
		selectRange.setStart(activeObj,CKEditorParams.editorObject.getSelection().getNative().focusOffset);
		selectRange.setEndAfter(parentPObj);
	}else{
	//backSpace按钮事件，从节点最开始获取到光标
		selectRange.setStartBefore(parentPObj);
		selectRange.setEnd(activeObj,CKEditorParams.editorObject.getSelection().getNative().focusOffset);
	}

	if(window.console)console.log('selectRange',selectRange);
	if(window.console)console.log('selectRange.toString()',selectRange.toString());
	var selectRangeText = selectRange.toString();
	lastChar = isDelKey?getFirstChar(selectRange.toString()) :getLastChar(selectRange.toString());
	if(lastChar == '') return;
	if(window.console)console.log('lastChar',lastChar);

	selectRange.detach();
	
	
	//删除插入的临时U标签
	if(CKEditorParams.editorObject.getSelection().getNative().focusNode.tagName == 'U' 
		&& CKEditorParams.editorObject.getSelection().getNative().focusNode.innerHTML.replace(/\u200B/g,'') == "")CKEditorParams.editorObject.getSelection().getNative().focusNode.remove();

	CKEditorParams.tempStr1 = selectRange.toString().slice(0,-1);

	insertDelChar(lastChar,isDelKey,event);

}
var moveToPreviousElementCount = 0;
/** 移动到前一节点 */
function moveToPreviousElement(selectedNode){


	var preNode = selectedNode.previousNode;

	//获取有内容的前一个子节点
	while(preNode == null || preNode.textContent == ''){
		if(selectedNode.tagName == 'P') break;
		preNode = selectedNode.parentNode.preNode;

		CKEditorParams.tempStr1 = preNode.textContent;
		preNode;
		
	}
	CKEditorParams.tempStr1 = preNode.textContent;

	if(selectedNode.previousNode == null && selectedNode.tagName != 'P' && moveToPreviousElementCount <= 20){
		selectedNode = selectedNode.parentNode;
		moveToPreviousElementCount++;
		moveToPreviousElement(selectedNode);
	}else if(selectedElement.$.tagName == 'P' && selectedElement.getPrevious() == null){
		return;
	}
	if(selectedElement.getPrevious().getText() == ""){
		try{
			moveToPreviousElement(selectedElement.getPrevious());
		}catch(e){}
	}
	
	// 将光标移至最末
	var range = CKEditorParams.editorObject.createRange();
	
	range.moveToElementEditEnd(selectedElement.getPrevious());

	range.select();
	range.scrollIntoView();
	CKEditorParams.tempStr1 = selectedElement.getPrevious().getText();
}
/** 将删除的内容生成修订痕迹 */
function insertDelChar(delWords,isDelKey){

	
	needAdd = true;
	// createdElement = '<del id="deltest_' + CKEditorParams.deleteId + '">' + lastChar +  '</del>';
	// createdElementid = "deltest_" + CKEditorParams.deleteId ;
	//判断后续节点是否为刚删除的内容

    var createdElement = CKEDITOR.dom.element.createFromHtml( '<s id="deltest_' + CKEditorParams.deleteId + '" class="odoc_delTag" xiudingren="' + CKEditorParams.author + '" xiudingshijian="' + getDate() + '"></s>' );
	if(delWords == ' '){
		createdElement.appendHtml('&nbsp;');
	}else{
		createdElement.appendText(delWords);
	}
	//DEL时，如果当前在S标签最后面，向后追加
	// if(isDelKey){
	// 	if( CKEditorParams.editorObject.getSelection().getNative().focusNode.parentNode.tagName == 'S' && CKEditorParams.editorObject.getSelection().getNative().focusNode.parentNode.className == 'odoc_delTag'){
	// 		createdElement.insertAfter(new CKEDITOR.dom.element( CKEditorParams.editorObject.getSelection().getNative().focusNode.parentElement));
	// 	}else{
	// 		CKEditorParams.editorObject.insertElement( createdElement );
	// 	}
	// }else{
	// 	if( CKEditorParams.editorObject.getSelection().getNative().focusNode.parentNode.tagName == 'S' && CKEditorParams.editorObject.getSelection().getNative().focusNode.parentNode.className == 'odoc_delTag'){
	// 		createdElement.insertBefore(new CKEDITOR.dom.element( CKEditorParams.editorObject.getSelection().getNative().focusNode.parentElement));
	// 	}else{
	// 		CKEditorParams.editorObject.insertElement( createdElement );
	// 	}
	// }
	CKEditorParams.editorObject.insertElement( createdElement );

	createdElement.innerText = delWords;
	//判断如果在S标签内删除，重新组合S标签


	var nowTime = getDate();
	//删除临时空标签
	for(var childCount = 0 ; childCount < createdElement.getParent().getChildCount();childCount++){
		var childNode = createdElement.getParent().$.childNodes[childCount];
		if( childNode.textContent && childNode.textContent.replace(/\u200B/g,'') == ""){
			childNode.remove();
			childCount--;
		}
	}

	//如果插入的S标签，包含在S标签内，DEL时处在父标签的最右侧，BACKSPACE时处于父标签的最左侧，将标签移动到父标签外边
	if(createdElement.getParent().$.tagName == 'S'){
		//DEL键，判断是否存在下一个节点,否则判断前一节点
		var nextNode = isDelKey?createdElement.$.nextSibling:createdElement.$.previousSibling;
		if(nextNode == null){
			var createdElementTemp = CKEDITOR.dom.element.createFromHtml( createdElement.getOuterHtml());

			if(isDelKey){
				createdElementTemp.insertAfter(createdElement.getParent());
			}else{
				createdElementTemp.insertBefore(createdElement.getParent());
			}
			createdElement.$.remove();
			createdElement = createdElementTemp;
		}else{
			// //如果要删除的内容是已经删除的，插入临时内容
			// var range = CKEditorParams.editorObject.createRange();

			// var uElement = CKEDITOR.dom.element.createFromHtml( '<u class="odoc_insertTag" >A</u>' );
			// uElement.insertAfter( createdElement );

			// range.moveToPosition( uElement, isDelKey?CKEDITOR.POSITION_AFTER_END:CKEDITOR.POSITION_BEFORE_START);
			// range.select();
			// createdElement.$.outerHTML = createdElement.getHtml();
			// uElement.remove();
			// return;
		}
	}
	var closestNode = isDelKey?createdElement.$.previousSibling:createdElement.$.nextSibling;
	if(closestNode != null ){
		if(closestNode && closestNode.tagName == 'S' && closestNode.className == 'odoc_delTag' && closestNode.getAttribute("xiudingshijian")){
			//2019-01-17T19:43:42Z
			//合并最近删除的内容
			var numNowTime = parseInt(nowTime.replace(/-/g,'').replace(/:/g,'').replace(/T/g,'').replace(/Z/g,''),10);
			var numXiudingshijian = parseInt(closestNode.getAttribute("xiudingshijian").replace(/-/g,'').replace(/:/g,'').replace(/T/g,'').replace(/Z/g,''),10);
			if(numNowTime <= numXiudingshijian + 100 && closestNode.getAttribute("xiudingren") == CKEditorParams.author){
				//DEL时，向后追加
				if(isDelKey){
					closestNode.innerHTML = closestNode.innerHTML + createdElement.$.innerHTML;
				}else{
					closestNode.innerHTML = createdElement.$.innerHTML + closestNode.innerHTML;
				}
				closestNode.setAttribute("xiudingshijian",nowTime);
				createdElement.$.remove();
				
				setSingleReviseItem(closestNode,'del');
				focusEditor(closestNode.id,isDelKey);
				return;
			}
			
		}
	}
	setSingleReviseItem(createdElement,'del');
	
	focusEditor('deltest_' + CKEditorParams.deleteId,isDelKey);
	

}
/** 删除选中内容 */
function deleteSelected(event,isDelKey){
	insertDelChar(event.editor.getSelection().getSelectedText(),isDelKey,event);

}

/** 修订，批注信息，鼠标悬停 显示批注信息 */
function showInfo(e){
	var eDom = e.target;
	var popoverDom = document.getElementsByClassName("popover")[0]
	if(e.target.nodeName == "U" || e.target.nodeName == "S"){
		//隐藏修订时不显示
		if(!CKEditorParams.showrevision) return;
		if(CKEditorParams.hoverDom == e.target.getAttribute("id")){
			return ;
		}else{
			CKEditorParams.hoverDom = e.target.getAttribute("id");
		}
		var positionX = e.x+20;
		var positionY = e.y+20;
		var type ="插入的内容";
		if(e.target.nodeName == "S"){
			type = "删除的内容";
		}
		
		var dateStr = getTagTime(eDom.getAttribute("xiudingshijian"))
		var author = eDom.getAttribute("xiudingren")
		var html ='<div class="popover-info"><span class="popover-author">'+author+'</span><span class="popover-time">'+dateStr+'</span><span class="popover-type">'+type+'</span></div><div class="popover-content">'+eDom.innerText+'</div>'
		popoverDom.innerHTML = html;
		popoverDom.style.display = "block";
		popoverDom.style.top = positionY+"px";
		popoverDom.style.left = positionX+"px";
	}else if(e.target.nodeName == "SPAN" && (e.target.getAttribute("class")=="odoc_postilWord" || e.target.parentNode.getAttribute("class")=="odoc_postilWord")){

		if(CKEditorParams.hoverDom ==  e.target.getAttribute("id")){
			return;
		}else{
			CKEditorParams.hoverDom = e.target.getAttribute("id");
		}
		var positionX = e.x+20;
		var positionY = e.y+20;
		var dateStr = getTagTime(eDom.getAttribute("pizhushijian"));
		var author = eDom.getAttribute("pizhuren");
		var pizhuneirong = eDom.getAttribute("pizhuneirong");
		var html ='<div class="popover-info"><span class="popover-author">'+author+'</span><span class="popover-time">'+dateStr+'</span><span class="popover-type">批注的内容</span></div><div class="popover-content">'+pizhuneirong+'</div>'
		popoverDom.innerHTML = html;
		popoverDom.style.display = "block";
		popoverDom.style.top = positionY+"px";
		popoverDom.style.left = positionX+"px";
	}else{
		popoverDom.style.display = "none";
		CKEditorParams.hoverDom="";
	}
}

/** 隐藏提示信息 */
function hideTip(){
	document.getElementsByClassName("ant-modal-content")[0].style.display = "none" 
}





/*------------------------------外部调用的方法-------------------------------*/


/** 显示隐藏批注
 * params: bool 显示/隐藏
 */
function showPostilList(bool){
	//是否显示批注
	CKEditorParams.showPost = !bool;
	
	var postilList = iframeDocument.getElementsByClassName("odoc_postilWord");
	for(var i=0; i< postilList.length ;i++){
		if(CKEditorParams.showPost){
			jQuery(postilList[i]).removeClass('hiddenPositl');
		}else{
			jQuery(postilList[i]).addClass('hiddenPositl');
		}
	}
	var postil =  document.getElementsByClassName("postil")[0];
	if(!bool){
		postil.style.display="block";
	}else{
		postil.style.display="none";
	}
}

/** 显示修订 */
function showReviseList(bool){
	
	var revise =  document.getElementsByClassName("revise")[0];
	if(!bool){
		revise.style.display="block";
	}else{
		revise.style.display="none";
	}	
	
	//编辑区域的修订显示隐藏
	CKEditorParams.showrevision = !bool;
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	var delList = iframeBody.getElementsByTagName("s")
	var insList = iframeBody.getElementsByTagName("u")
	
	if(!bool){
		for(var i =0; i < delList.length;i++){
			jQuery(delList[i]).removeClass('hiddenRevision_s');
		}
		for(var i =0; i < insList.length;i++){
			jQuery(insList[i]).removeClass('hiddenRevision_u');
		}
	}else{

		for(var i =0; i < delList.length;i++){
			jQuery(delList[i]).addClass('hiddenRevision_s');
		}
		for(var i =0; i < insList.length;i++){
			jQuery(insList[i]).addClass('hiddenRevision_u');
		}
	}
}

/** 导入word的时候获取修订内容 */
function getReviseItem(){
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	var delList = iframeBody.getElementsByTagName("s")
	var insList = iframeBody.getElementsByTagName("u")
	var reviseContent = document.getElementsByClassName("revise-content")[0];
	reviseContent.innerHTML = ""
	reviseContent.reviseCount = 0;
	CKEditorParams.reviseCount = 0;
	setReviseItem(delList,"删除的内容")
	setReviseItem(insList,"插入的内容")
	document.getElementsByClassName("title-number")[0].innerText=CKEditorParams.reviseCount+"处修订";
}

/** 导入文件时创建修订的内容 */
function setReviseItem(listArr,type){
	
	for(var i=0; i< listArr.length ;i++){
		setSingleReviseItem(listArr[i],type);
		// CKEditorParams.reviseCount += 1;
		// var div = document.createElement("div");
		// div.setAttribute("class","revise-item");
		// div.setAttribute("id","reviseItem"+CKEditorParams.reviseCount);
		// var dateStr = getTagTime(listArr[i].getAttribute("xiudingshijian"))
		// var xiudingren = listArr[i].getAttribute("xiudingren");
		// var html = '<div class="revise-top"><span class="revise-item-name">'+xiudingren+'</span><span class="revise-item-type">'+type+'</span></div><div class="postilTime">'+dateStr+'<div class="revise-bottom">'+listArr[i].innerText+'</div>';
		// div.innerHTML = html;
		// boxDom.appendChild(div);
	}

}
/** 设置单个修订信息 */
function setSingleReviseItem(element,type){
		if(type == 'del'){
			type = "删除的内容";
		}else if(type == 'ins'){
			type = "插入的内容";
		}
		var boxDom = document.getElementsByClassName("revise-content")[0];
		var div;
		//如果修订信息已存在，则不进行添加
		if(element.getAttribute("id") != null && element.getAttribute("id") != '' && jQuery('div[revsiseid="' + element.getAttribute("id") + '"]').length > 0){
			div = jQuery('div[revsiseid="' + element.getAttribute("id") + '"]')[0];
		}else{
			div = document.createElement("div");
			CKEditorParams.reviseCount += 1;
		}
		div.setAttribute("class","revise-item");
		div.setAttribute("id","reviseItem"+CKEditorParams.reviseCount);
		div.setAttribute("revsiseid",element.getAttribute("id"));
		var dateStr = getTagTime(element.getAttribute("xiudingshijian"))
		var xiudingren = element.getAttribute("xiudingren");
		var html = '<div class="revise-top"><span class="revise-item-name">'+xiudingren+'</span><span class="revise-item-type">'+type+'</span></div><div class="postilTime">'+dateStr+'<div class="revise-bottom">'+element.innerText+'</div>';
		div.innerHTML = html;
		boxDom.appendChild(div);
		recountReviseNumber();
}

/** 渲染批注信息 */
function getPositlItem(){
	var postilList = iframeDocument.getElementsByClassName("odoc_postilWord");
	CKEditorParams.endorseId = 0;
	document.getElementById("postilBox").innerHTML = ""
	for(var i=0; i< postilList.length ;i++){
		CKEditorParams.endorseId ++;
		var div = document.createElement("div");
		div.setAttribute("class","postilItem");
		div.setAttribute("id","postilItem"+CKEditorParams.endorseId);		
		var dateStr = getTagTime(postilList[i].getAttribute("pizhushijian"))
		var pizhuren = postilList[i].getAttribute("pizhuren");
		var pizhuneirong = postilList[i].getAttribute("pizhuneirong")
		//不显示批注信息时
		if(!CKEditorParams.showPost) jQuery(postilList[i]).addClass('hiddenPositl');
		var insertHtmlString='<div class="headPortrait"><span class="odoc_author">'+pizhuren+'</span></div><div class="postilContent"><div class="postilTime">'+dateStr+'</div><div class="postilText">'+pizhuneirong+'</div></div>'	;
		div.innerHTML = insertHtmlString;
		document.getElementById("postilBox").appendChild(div)
	}
	document.getElementById("postilNumber").innerText=CKEditorParams.endorseId+"处修订";
}

/** 获取时间 */
function getTagTime(time){
	return time?time.replace("T","&nbsp;").replace("Z",""):'';
}

/** 点击接受修订 */
function clickReceiveRevise(){
	if(window.console)console.log("clickReceiveRevise")
}
/**
 * 接受修订
 * @param 
 */
function receiveRevise(isAccept,needMoveToNext,acceptAll){
	
	// for(var i =0; i < CKEditorParams.editorObject.document.getElementsByTag('u').count();i++){
	// 	AllReviseList.push(CKEditorParams.editorObject.document.getElementsByTag('u').getItem(i));
	// }
	// for(var i =0; i < CKEditorParams.editorObject.document.getElementsByTag('s').count();i++){
	// 	AllReviseList.push(CKEditorParams.editorObject.document.getElementsByTag('s').getItem(i));
	// }

	var AllReviseList = getAllReviseList();
	if(!acceptAll){
		
		if(AllReviseList.length > 0){
			if(!needMoveToNext){
				focusEditor(AllReviseList[0].id);
			}
			receiveReviseOne(isAccept,AllReviseList[0]);
		}
		if(needMoveToNext && AllReviseList.length > 1){
			focusEditor(AllReviseList[1].id);
		}
	}else{
		for(var i = 0; i < AllReviseList.length; i++){
			receiveReviseOne(isAccept,AllReviseList[i]);
		}
	}
}
/** 获取修订列表 */
function getAllReviseList(){

	iframeDocument = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument;
	iframeWindow = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentWindow;
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	
	var AllReviseList = new Array();
	
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	var delList = iframeBody.getElementsByTagName("s")
	var insList = iframeBody.getElementsByTagName("u")
	for(var i =0; i < delList.length;i++){
		AllReviseList.push(delList[i]);
	}
	for(var i =0; i < insList.length;i++){
		AllReviseList.push(insList[i]);
	}
	//按照ID排序
	AllReviseList = AllReviseList.sort(sortId);
	return AllReviseList;
}
//点击接受并移到下一处
function receiveReviseAndMoveToNext(){
	receiveRevise(true,true);
}
//接受此修订
function receiveOneRevise(){
	receiveRevise(true,false);
}
//接受所有修订
function receiveAllRevise(){
	receiveRevise(true,false,true);
}
//点击拒绝
function clickRejectRevise(){
	if(window.console)console.log("clickReject")
}
//拒绝并移到下一处
function rejectReviseAndMoveToNext(){
	receiveRevise(false,true);
}
//拒绝此修订
function rejectOneRevise(){
	receiveRevise(false,false);
}
//拒绝所有修订
function rejectAllRevise(){
	receiveRevise(false,false,true);
}
//计数选中第几个修订
var selectedReviseNum = 0;
//上一处修订
function findPrevious(){
	var AllReviseList = getAllReviseList();
	if(AllReviseList.length <= 0) return;
	if(selectedReviseNum < 0){
		selectedReviseNum = 0;
	}
	if(selectedReviseNum >= AllReviseList.length){
		selectedReviseNum = AllReviseList.length - 1;
	}
	focusEditor(AllReviseList[selectedReviseNum].id);
	selectedReviseNum--;
	if(selectedReviseNum < 0){
		selectedReviseNum = AllReviseList.length - 1;
	}
	if(selectedReviseNum >= AllReviseList.length){
		selectedReviseNum = 0;
	}
}

//下一处修订
function findNext(){
	var AllReviseList = getAllReviseList();
	if(AllReviseList.length <= 0) return;
	if(selectedReviseNum >= AllReviseList.length){
		selectedReviseNum = AllReviseList.length - 1;
	}
	if(selectedReviseNum < 0){
		selectedReviseNum = 0;
	}
	focusEditor(AllReviseList[selectedReviseNum].id);
	selectedReviseNum++;
	if(selectedReviseNum >= AllReviseList.length){
		selectedReviseNum = 0;
	}
	if(selectedReviseNum < 0){
		selectedReviseNum = AllReviseList.length - 1;
	}
}
function sortId(a,b){
	return a.id - b.id;
}
function receiveReviseOne(isAccept,ele){
	//for(var i = 0; i < AllReviseList.length; i++){
		if(isAccept){
			if(ele.tagName == 'U'){
				ele.outerHTML = ele.innerHTML;
			}else if(ele.tagName == 'S'){
				ele.remove();
			}
		}else{
			if(ele.tagName == 'S'){
				ele.outerHTML = ele.innerHTML;
			}else if(ele.tagName == 'U'){
				ele.remove();
			}
		}
		//重新渲染修订列表
		getReviseItem();
	//	break;
	//}
}
//判断是否编辑内容
function iseditArea(ele){
	return ele.parentNode.nodeName == 'P';
}

//计数选中第几个批注
var selectedPostilNum = 0
//上一条批注
function findPreviousItem(){
	
	var AllPostilList = getByClassesAndId(['odoc_postilWord']);
	if(AllPostilList.length <= 0) return;
	if(selectedPostilNum < 0){
		selectedPostilNum = 0;
	}
	if(selectedPostilNum >= AllPostilList.length){
		selectedPostilNum = AllPostilList.length - 1;
	}
	focusEditorByItem(AllPostilList[selectedPostilNum]);
	selectedPostilNum--;
	if(selectedPostilNum < 0){
		selectedPostilNum = AllPostilList.length - 1;
	}
	if(selectedPostilNum >= AllPostilList.length){
		selectedPostilNum = 0;
	}
	
}
//下一条批注
function findNextItem(){
	
	var AllPostilList = getByClassesAndId(['odoc_postilWord']);
	if(AllPostilList.length <= 0) return;
	if(selectedPostilNum >= AllPostilList.length){
		selectedPostilNum = AllPostilList.length - 1;
	}
	if(selectedPostilNum < 0){
		selectedPostilNum = 0;
	}
	focusEditorByItem(AllPostilList[selectedPostilNum]);
	selectedPostilNum++;
	if(selectedPostilNum >= AllPostilList.length){
		selectedPostilNum = 0;
	}
	if(selectedPostilNum < 0){
		selectedReviseNum = AllPostilList.length - 1;
	}
}
//htmlDOM获取焦点
function focusEditorByItem(ele)
{
	var element = new CKEDITOR.dom.element(ele);
	focusEditorByCkItem(element);
}
/**
 * CK DOM获取焦点
 * element:CK Element
 * isend:是否移动到结束位置
 */
function focusEditorByCkItem(element,isend)
{
	// 获取焦点
	CKEditorParams.editorObject.focus();

	// 将光标移至最末
	var range = CKEditorParams.editorObject.createRange();
	if(isend){
		range.moveToElementEditEnd(element);
	}else{
		range.moveToElementEditStart(element);
	}

	range.select();
	range.scrollIntoView();
}
//根据ID获取焦点
function focusEditor(tempid,isDelKey)
{
	// 获取焦点
	CKEditorParams.editorObject.focus();

	// 将光标移至最末
	var range = CKEditorParams.editorObject.createRange();
	//是否是DEL事件
	if(isDelKey){

		range.moveToElementEditEnd(CKEditorParams.editorObject.document.getById(tempid));
		// if(CKEditorParams.editorObject.document.getById(tempid).$.nextSibling){
		// 	var nextSiblingElement = CKEDITOR.dom.element(CKEditorParams.editorObject.document.getById(tempid).$.nextSibling);
		// 	range.moveToElementEditStart(nextSiblingElement);
		// }else{
		// 	range.moveToElementEditEnd(CKEditorParams.editorObject.document.getById(tempid));
		// }
	}else{
		range.moveToElementEditStart(CKEditorParams.editorObject.document.getById(tempid));
	}

	range.select();
	range.scrollIntoView();

}
//重新计算修订内容
function recountRevise(){

		iframeDocument = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument;
		iframeWindow = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentWindow;
		var iframeBody = iframeDocument.getElementsByTagName("body")[0];
		if(bool){
			var delList = iframeBody.getElementsByTagName("u")
			var insList = iframeBody.getElementsByTagName("s")
			var reviseContent = document.getElementsByClassName("revise-content")[0];
			reviseContent.innerHTML = ""
			reviseContent.reviseCount = 0;
			for(var i=0; i< delList.length ;i++){
				CKEditorParams.reviseCount += 1;
				var div = document.createElement("div");
				div.setAttribute("class","revise-item")
				div.setAttribute("id","reviseItem"+CKEditorParams.reviseCount)
				var dateStr = delList[i].getAttribute("xiudingshijian");
				dateStr = dateStr.replace("T","&nbsp;").replace("Z","");

				var html = '<div class="revise-top"><span class="revise-item-name">'+CKEditorParams.author+'</span><span class="revise-item-type">删除的内容</span></div> <div class="postilTime">'+dateStr+'</div><div class="revise-bottom">'+delList[i].innerText+'</div>';
				div.innerHTML = html;
				reviseContent.appendChild(div);

			}

			for(var i=0; i< insList.length ;i++){
				CKEditorParams.reviseCount += 1;
				var div = document.createElement("div");
				div.setAttribute("class","revise-item");
				div.setAttribute("id","reviseItem"+CKEditorParams.reviseCount);

				var dateStr = insList[i].getAttribute("xiudingshijian");
				dateStr = dateStr.replace("T","&nbsp;").replace("Z","");

				var html = '<div class="revise-top"><span class="revise-item-name">'+CKEditorParams.author+'</span><span class="revise-item-type">插入的内容</span></div><div class="postilTime">'+dateStr+'<div class="revise-bottom">'+insList[i].innerText+'</div>';
				div.innerHTML = html;
				reviseContent.appendChild(div);
			}
			document.getElementsByClassName("title-number")[0].innerText=CKEditorParams.reviseCount+"处修订";
			
		}
}
function recountReviseNumber(){
	document.getElementsByClassName("title-number")[0].innerText=CKEditorParams.reviseCount+"处修订";
}

var count = 0;
//根据选中内容的class，切换样式的选中效果
function resetSelectedClass(element){
	var baseNode = element.baseNode;
	if(baseNode.nodeName != 'P'){
		getPTagNodecount = 0;
		baseNode = getPTagNode(baseNode,0);
	}
	var selectedClassName = baseNode.className.trim();
	if(selectedClassName == 'odoc_shuming1'
	   || selectedClassName == 'odoc_xuhao1'
	   || selectedClassName == 'odoc_xuhao2' 
	   || selectedClassName == 'odoc_xuhao3' 
	   || selectedClassName == 'odoc_chengwenriqi1' ){
		selectedClassName = selectedClassName.substring(0,selectedClassName.length - 1);
	}

	if(selectedClassName != ''){
		for(var i = 0; i <parent.jQuery('.odoc_style').length; i++){
			var ele = parent.jQuery('.odoc_style')[i];
			if(parent.jQuery(ele).hasClass(selectedClassName)){
				parent.jQuery('.wea-odoc-onlineEdit-toolsBar-style-single-active').removeClass("wea-odoc-onlineEdit-toolsBar-style-single-active");
				parent.jQuery(ele).addClass("wea-odoc-onlineEdit-toolsBar-style-single-active");
				break;
			}
		}
	}
	
}
//获取P标签的父节点
function getPTagNode(baseNode,getPTagNodecount){
	if(getPTagNodecount === undefined) getPTagNodecount = 0;
	getPTagNodecount++;
	parentNode = baseNode.parentNode;
	if(getPTagNodecount <= 10 && parentNode.nodeName != 'P'){
		parentNode = getPTagNode(parentNode,getPTagNodecount);
	}
	return parentNode;

}
//打印
function odocprint(){
	
	//var revise = document.getElementsByClassName("revise")[0];
	//var tempdisplay = revise.style.display;
	//revise.style.display="none";
	//CKEditorParams.editorObject.execCommand('preview');
	//CKEditorParams.editorObject.execCommand('print');
	
	//CKEDITOR.tools.callFunction(4);
	
	jQuery(".cke_wysiwyg_frame")[0].contentWindow.print();
	//revise.style.display=tempdisplay;
}
//根据标签和ID获取元素
function getByTagsAndId(TagNames,id){
	
	iframeDocument = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument;
	iframeWindow = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentWindow;
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	
	var AllEleList = new Array();
	
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];

	for(var i = 0; i < TagNames.length; i++){
		var tempList = iframeBody.getElementsByTagName(TagNames[i])
		for(var j =0; j < tempList.length;j++){
			if(id && id > 0 && tempList[j].id == id){
				return tempList[j];
			}
			AllEleList.push(tempList[i]);
		}

	}
	//按照ID排序
	AllEleList = AllEleList.sort(sortId);

	return AllEleList;

}
//根据class和ID获取元素
function getByClassesAndId(classNames,id){
	
	iframeDocument = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentDocument;
	iframeWindow = document.getElementsByClassName('cke_wysiwyg_frame')[0].contentWindow;
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];
	
	var AllEleList = new Array();
	
	var iframeBody = iframeDocument.getElementsByTagName("body")[0];

	for(var i = 0; i < classNames.length; i++){
		var tempList = iframeBody.getElementsByClassName(classNames[i])
		for(var j =0; j < tempList.length;j++){
			if(id && id > 0 && tempList[j].id == id){
				return tempList[j];
			}
			AllEleList.push(tempList[j]);
		}

	}
	//按照ID排序
	AllEleList = AllEleList.sort(sortId);

	return AllEleList;

}
//判断后续节点是否为刚删除的内容
function justDeleted(isDel){
	CKEditorParams.editorObject.getSelection().getStartElement()

}